package examples;

import java.io.*;
import java.net.Socket;

public class TcpClientDemo02 {
    public static void main(String[] args) {
        try {
            Socket socket = new Socket("127.0.0.1", 6666);

            InputStream inputStream = new FileInputStream(new File("D:\\123.jpg"));
            OutputStream out = socket.getOutputStream();
            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

            int len = 0;
            byte[] bytes = new byte[1024];
            while ((len = inputStream.read(bytes)) != -1) {
                out.write(bytes, 0, len);
            }
            socket.shutdownOutput();

            String result = in.readLine();
            System.out.println(result);

            inputStream.close();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
